#ifndef _MAP_H_
#define _MAP_H_

#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <stdio.h>
#include <iostream>
#include <fstream>
#include <vector>
#include "SpriteManager.h"
#include "Unit.h"

using namespace sf;

#define TILE_SIZE 64

enum {
    TR_GRASS = 0,
    TR_DIRT,
    TR_STONE,
    TR_WATER,
};

class Unit;
class SpriteManager;

struct Tile {
    Sprite sprite;
    int terrain;
    Unit *unit;
};

class Map {
    private:
        Image terrainImages[5];
        int width; // number of Tiles in x-dimension
        int height; // number of Tiles in y-dimension
        Tile *tileMap;      // array to hold tiles
        std::vector<Unit*> &units;

    public:
        Map(std::vector<Unit*> &units);
        ~Map();

        int GetWidth();
        int GetHeight();
        
        Tile *GetTile(int x, int y);
        Unit *GetTileUnit(int x, int y);
        void MoveUnit(int oldX, int oldY, int newX, int newY);

        void PopulateTiles();

        bool Load(const char *fileName);
        void UnLoad();
        void Update(float dt);
        void Render(SpriteManager &spriteManager);
};

#endif
